/// [Reciprocal cycles](https://projecteuler.net/problem=26)
fn main() {
    let num_vec = (1..1000).map(|n| reciprocal_cycles(n)).collect::<Vec<u32>>();
    let mut num = 0;
    let mut max = 0;
    for (i, v) in num_vec.iter().enumerate() {
        if *v > max {
            num = i + 1;
            max = *v;
        }
    }
    println!("{},{}", num, max);
}
fn reciprocal_cycles(n: u128) -> u32 {
    let mut m = n;
    while m % 2 == 0 {
        m /= 2;
    }
    while m % 5 == 0 {
        m /= 5;
    }
    let mut e = 1;
    while big_num_mod(e, m) != 0 {
        e += 1;
    }
    e
}
fn big_num_mod(e: u32, m: u128) -> u128 {
    let big_digit = 30;
    let mut exp = e;
    let mut rst = 1;
    while exp > big_digit {
        let x = big_digit - rst.to_string().len() as u32;
        rst *= 10_u128.pow(x);
        exp -= x;
        rst %= m;
    }
    rst *= 10_u128.pow(exp);
    (rst - 1) % m
}
